"""主脚本
"""
import os
from app import create_app, db
from app.models import User, Role
from flask_migrate import Migrate

app = create_app(os.getenv("FLASK_ENV") or "default")
migrate = Migrate(app, db)


@app.shell_context_processor
def make_shell_context():
    return dict(db=db, User=User, Role=Role)


@app.cli.command()  # 添加自定义命令运行单元测试 flask test
def test():
    """运行单元测试"""
    import unittest
    tests = unittest.TestLoader().discover('tests')
    unittest.TextTestRunner(verbosity=2).run(tests)


if __name__ == "__main__":
    # 可设置 FLASK_ENV 再运行主脚本
    # 或设置 FLASK_APP 和 FLASK_ENV 再运行 flask run
    app.run()
